package com.api.devices.domain.query;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.api.common.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils;

import java.util.*;

@Getter
@Setter
public class MonitoredQuery {
    private String monitoredCode;
    private Long groupId;
    private String ipcCode;
    private JSONObject monitoredNameLocales;
    private Set<String> datColSet;
    /**
     * 描述
     */
    private String remark;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 创建人
     */
    private String createBy;
    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    /**
     * 更新人
     */
    private String updateBy;

    public void setMonitoredNameLocales(String monitoredNameLocales) {
        this.monitoredNameLocales = JSONObject.parseObject(monitoredNameLocales);
    }

    public void setDatColSet(String datColSet) {
        if (StringUtils.isNotBlank(datColSet)) {
            List<String> ja = JSONArray.parseArray(datColSet).toList(String.class);
            this.datColSet = new HashSet<>(ja);
        } else {
            this.datColSet = null;
        }
    }
}